<?php
namespace jy_stpinggou;
defined('BY_JYA') or exit('error');
/*
	任务解锁
*/
class renwu extends \plugin{
	/*
		downs
	*/
	public function canyu($params,$pinggoods=array()){
		$fromuser=pdo_getcolumn('jy_stteamfee_team',array('mid'=>$params['mid'],'uniacid'=>$_SESSION['uniacid']),'fromuser');
		$isnew=pdo_count('jy_stpinggou_log',array('status'=>1,'type'=>0,'mid' =>$params['mid']),'id');
		//第一次参与，有释放虚拟币机会！
		if($isnew==1){
			$this->up_daycanyus($fromuser);
		}
		$this->create_fee($fromuser,$params['mid']);
		/*if($this->plugin_exists('jy_stteamfee')){
			model('jy_stteamfee/commission')->create($params);
		}
		if($this->plugin_exists('jy_area_agent')){
			model('jy_area_agent/commission')->create($params);
		}*/
		//升级
		$this->model('member')->update_agent_level($fromuser);
		//自购升级
		$this->model('member')->update_agent_level($params['mid'],true,$pinggoods);
		return false;
	}
	public function canfen($params,$pinggoods=array()){
		$this->model('commission')->order_complete($params);
		return false;
	}
	public function create_fee($fromuser,$mid=0){
		$this->create_commission($fromuser,$mid);
		return false;
	}
	/*
		每直推一个会员参与拼团奖励N个能量值个;
	*/
	function create_commission($fromuser,$mid=0){
			$isget=pdo_get('jy_stteamfee_team',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
			if($isget['is_jifen6']==$fromuser){
				return false;
			}
			$jifen6=$this->fenxiaoset['jifen6'];
			if($jifen6>0){
				model('core/member')->member_credit($fromuser,'credit6',$jifen6,true,'jy_stpinggou','直推会员拼团获得奖励');
				pdo_update('jy_stteamfee_team',array('is_jifen6'=>$fromuser),array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
			}
			return true;
	}
	/*
		更新进入新参与;
	*/
	function up_daycanyus($mid){
		$this->model('member')->up_tixianfee($mid,true);
		$dayid=pdo_getcolumn('jy_stpinggou_member',array('mid'=>$mid),'dayid');
		$newdayid=date('Y-m-d',TIMESTAMP);
		if($dayid==$newdayid){
			pdo_update('jy_stpinggou_member',array('daycanyus +='=>1),array('mid'=>$mid));
		}else{
			pdo_update('jy_stpinggou_member',array('daycanyus'=>1,'dayid'=>$newdayid),array('mid'=>$mid));
		}
		return true;
	}
}